import { JSEncrypt } from 'jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxZ3AnPrB73styOk7Vk+3\n' +
  'Opwg6fk6R0M0xU2LX0u2B78b2ExDZkLDTWc4zusRZbipM+dYwy3GBpa4y9lSt8Es\n' +
  '02d1AQcwAZUgkgmCyUiz3xU362e5K/XclcxG2g2q9KSSCB95rwohbCK3aNMsHI2p\n' +
  'kNyVe40/OsJ8IsLzoS6YAgE3Wd3+uQ8FG5/UHWkF1OCWwIeDqEi9bfLXSdqAWo7A\n' +
  'YVzsRfHfSM1DtOOP5ub2+9nBB2BREVPui5CvmkV8zT2qr5jt32j6D5+TbCkV269P\n' +
  'BaJnypyRNGUp9+XAHW428FLXkY0UbI+4heLyaJkO6X5u2o0MiBgMI1ncMxrOWqKp\n' +
  'RQIDAQAB'

const privateKey =
  'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDFncCc+sHvey3I\n' +
  '6TtWT7c6nCDp+TpHQzTFTYtfS7YHvxvYTENmQsNNZzjO6xFluKkz51jDLcYGlrjL\n' +
  '2VK3wSzTZ3UBBzABlSCSCYLJSLPfFTfrZ7kr9dyVzEbaDar0pJIIH3mvCiFsIrdo\n' +
  '0ywcjamQ3JV7jT86wnwiwvOhLpgCATdZ3f65DwUbn9QdaQXU4JbAh4OoSL1t8tdJ\n' +
  '2oBajsBhXOxF8d9IzUO044/m5vb72cEHYFERU+6LkK+aRXzNPaqvmO3faPoPn5Ns\n' +
  'KRXbr08FomfKnJE0ZSn35cAdbjbwUteRjRRsj7iF4vJomQ7pfm7ajQyIGAwjWdwz\n' +
  'Gs5aoqlFAgMBAAECggEBAIJfyiSG1w3NAW7MWMZfvy2etaRHNeiv8Q++UhXj2EsS\n' +
  'DSfNYKYFo93cHMF+mjK2+oJwvcG+4CeWpoJudUEf5Bfw6GNuP4C7xwox1iQ/n9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GufPoFxY/mOYGFydNqoPDwqkmu8/KXFHt5TAp3c4ilhz/\n' +
  '+xxJUPMNQ94IuCK5j349CVoPd3N6YDu1XmKoa8ndG9OSlslUbvau+GiIDxMYQExt\n' +
  'hX5020TZZn/V6Z8QuEmO+9Wj'

// 加密
export const encrypt = (txt: string) => {
  const encryptor = new JSEncrypt()
  // 设置公钥
  encryptor.setPublicKey(publicKey)
  // 对数据进行加密
  return encryptor.encrypt(txt)
}

// 解密
export const decrypt = (txt: string) => {
  const encryptor = new JSEncrypt()
  // 设置私钥
  encryptor.setPrivateKey(privateKey)
  // 对数据进行解密
  return encryptor.decrypt(txt)
}
